﻿using System;
using System.Collections.Generic;
using System.Text;
using SwinGame;

namespace NeuralNetwork.src
{
    class Bug
    {
        double _x;
        double _y;
        NeuralNet _neuralNet = new NeuralNet();


        public Bug(Random rand, int x, int y) { _neuralNet.SetUp(2, 10, 3, 2, rand); _x = x; _y = y; }

        void Motor(double MouseX, double MouseY)
        {
            double dx = MouseX - _x;
            double dy = MouseY - _y;

            double dist = Math.Sqrt( (dx * dx) + (dy * dy));
            dx /= dist;
            dy /= dist;
            //Normalise?

            double[] op = _neuralNet.GetOutput(new double[2] { dx, dy });
            _x += op[1] - 0.5;
            _y += op[0] - 0.5;
        }

        public void Update(double dt,Random rand, Point2D mousePos)
        {
            if (_y < 0 || _y > 600) { _y = 300; _neuralNet.GetMutated(1, rand); }
            if (_x < 0 || _x > 800) { _x = 400; _neuralNet.GetMutated(1, rand); }
            //Point2D mp  = SwinGame.Input.MousePosition();   //move out
            Motor(mousePos.X, mousePos.Y);
        }

        public void Draw(double dt)
        {
            Point2D p = new Point2D(); p.X = (float)_x;
            p.Y = (float)_y;
            Graphics.DrawCircle(System.Drawing.Color.Black,p,30);
        }
    }
}
